package cn.fboost.mtos.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

@Data
@Builder
public class Response implements Serializable {
    private int ret;
    private String msg;
    private Object data;

    public static class Ret {
        public static final int SUCCESS = 0;
        public static final int FAILURE = -1;
        public static final int TOKEN_INVALID = 1001;
    }

    public static class ResponseBuilder {
        public ResponseBuilder success() {
            return this.ret(Ret.SUCCESS);
        }

        public ResponseBuilder failure() {
            return this.ret(Ret.FAILURE);
        }
    }

    @JsonIgnore
    public boolean isSuccess() {
        return ret == Ret.SUCCESS;
    }
}
